package cn.weixin.service.token;

import javax.annotation.PostConstruct;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author Han
 */
@Component
public class TokenCenter {
	private static Logger logger = LoggerFactory.getLogger(TokenCenter.class);
	private static String ACCESS_TOEKN = null;
		
	public static String getToken(){
		if(StringUtils.isEmpty(ACCESS_TOEKN)){
			String token = TokenUtil.getToken();
			if(token == null){
				logger.error("请求token失败...");
			}
			ACCESS_TOEKN = token;
		}
		return ACCESS_TOEKN;
	}
	
	@Scheduled(cron = "0 0 0/1 * * ?")
	protected void work() {
		String token = TokenUtil.getToken();
		if(token != null){
			this.ACCESS_TOEKN = token;
		}
	}
	
}
